﻿using afirewall.core;
using ExcelConfig;
using ExcelConfig.Config;
using ExcelConfig.StoreAPI;
using oueb;
using oueb.react;

namespace afirewall
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            ConfigStoreHelper.EnterConfigStoreAPIConfig();
            ExcelConfigHelper.SetDefault("配置本地存放路径", "config");
            ExcelConfigHelper.SetDefault("TxCloud远端配置域", "txcloud");
            ExcelConfigHelper.SetDefault("TxCloud远端配置名", "c002");
            ExcelConfigHelper.SetDefault("塔子盾配置域", "afirewall");
            ExcelConfigHelper.SetDefault("塔子盾配置名", "tata");

            var config = new AppConfigStreamFile(ConfigStoreAPI.Download(AppConfig.Text("塔子盾配置域"), AppConfig.Text("塔子盾配置名")));
            var auth = new AfirewallAuthMap();
            auth.LoadAccounts(config, config.Array("用户表"), config.Array("密码表"));
            var server = new OuebServer(config.Array("监听地址"));
            server.UseCors(op =>
            {
                op.AllowAnyOrigin().AllowAnyHeaders().AllowAnyMethod();
            });
            var host = new AfirewallHost(auth);
            host.Mount(server);

            OuebReact.LoadWebPath(server, config.Text("前端目录"));
            server.Listen();
            Console.WriteLine("Taizi Started.");
            lock (server) while (server.Runing) Monitor.Wait(server, 2000);
            server.Shutdown();
            Console.WriteLine("Bye");
        }
    }
}
